package io.xiyou.order.listener;

import com.alibaba.fastjson.JSON;
import io.xiyou.order.api.IOrderService;
import io.xiyou.order.api.bo.AddOrderBO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName：DirectReceiver
 * @Author：西柚
 * @Date：2021/10/31 9:57 上午
 * @Versiion：1.0
 */
@Slf4j
@Component
@RabbitListener(queues = "active.queue.order")//监听的队列名称
public class RabbitMqListener {

    @Autowired
    private IOrderService orderService;

    @RabbitHandler
    public void process(AddOrderBO addOrderBO) {
        log.info("DirectReceiver消费者收到消息  : {}", JSON.toJSONString(addOrderBO));

        orderService.createOrder(addOrderBO);
    }

}
